const express = require("express");
const router = express.Router();
const { errs } = require("../status/status");
const { deterToken } = require("../util/index");
const pool = require("../util/mysql");
// const archiver = require('archiver')
// const fs = require('fs')
const path = require('path')


const url=path.join(__dirname,'/file')
router.use(express.static(url))


//中间件
router.use(["/Dashboard", "/downPackage"], (req, res, next) => {
  //中间件校验(业务需求不做)
  next()
});


//工作台获取信息
router.get("/Dashboard", (req, res) => {
  pool.getConnection(function (err, connection) {
    if (err) throw err;
    let sql = "select * from userlist where username=?";
    connection.query(sql, [req.query.username], (err, result) => {
      if (err) {
        res.status(500);
        res.send(errs("error"));
      } else {
        if (result.length == 1) {
          res.send({
            code: 200,
            msg: "success",
            data: result[0],
          });
        } else {
          res.send(errs("error"));
        }
      }
    });
  });
});



//返回安装包(手动拷贝)
const downPackage = (req, res) => {
  const {local}=require('../url')
  const urls=local+'user'+'/test.zip'
  res.send({
    code:200,
    msg:'success',
    data:{
      data:urls
    }
  })
}


router.get('/downPackage', (req, res) => {
  downPackage(req, res)
})






module.exports = router;
